package com.springboot.code.config;

import lombok.Data;

/**
 * DESC:统一结果集封装
 *
 * @author WangJie
 * @date Created in 2023-05-24 22:00
 */
@Data
public class ApiResult<T> {

    //响应码
    private Integer code;

    //响应信息
    private String message;

    //响应结果
    private T data;

    public ApiResult() {}

    /**
     * 配合静态对象直接设置 data 参数
     * @param
     * @return ApiResult
     */
    public static<T> ApiResult<T> success() {
        ApiResult<T> ApiResult = new ApiResult<>();
        ApiResult.setCode(ResultCode.RC200.getCode());
        ApiResult.setMessage(ResultCode.RC200.getMessage());
        return ApiResult;
    }

    /**
     * 配合静态对象直接设置 data 参数
     * @param data
     * @return ApiResult
     */
    public static<T> ApiResult<T> success(T data) {
        ApiResult<T> ApiResult = new ApiResult<>();
        ApiResult.setCode(ResultCode.RC200.getCode());
        ApiResult.setMessage(ResultCode.RC200.getMessage());
        ApiResult.setData(data);
        return ApiResult;
    }

    /**
     * 配合静态对象直接设置 ApiResult 参数
     * @param resultCode
     * @return ApiResult
     */
    public static<T> ApiResult<T> success(ResultCode resultCode) {
        ApiResult<T> result = new ApiResult<>();
        result.setCode(resultCode.getCode());
        result.setMessage(resultCode.getMessage());
        return result;
    }

    /**
     * 配合静态对象直接设置 ApiResult 参数
     * @param resultCode
     * @param data
     * @return ApiResult
     */
    public static<T> ApiResult<T> success(ResultCode resultCode, T data) {
        ApiResult<T> result = new ApiResult<>();
        result.setCode(resultCode.getCode());
        result.setMessage(resultCode.getMessage());
        result.setData(data);
        return result;
    }

    /**
     * 配合静态对象直接设置 ApiResult 参数
     * @return ApiResult
     */
    public static<T> ApiResult<T> failure() {
        ApiResult<T> result = new ApiResult<>();
        result.setCode(ResultCode.RC999.getCode());
        result.setMessage(ResultCode.RC999.getMessage());
        return result;
    }

    /**
     * 配合静态对象直接设置 ApiResult 参数
     * @return ApiResult
     */
    public static<T> ApiResult<T> failure(String message) {
        ApiResult<T> result = new ApiResult<>();
        result.setCode(ResultCode.RC999.getCode());
        result.setMessage(message);
        return result;
    }

    /**
     * 配合静态对象直接设置 ApiResult 参数
     * @param resultCode
     * @return ApiResult
     */
    public static<T> ApiResult<T> failure(ResultCode resultCode) {
        ApiResult result = new ApiResult();
        result.setCode(resultCode.getCode());
        result.setMessage(resultCode.getMessage());
        return result;
    }

    /**
     * 配合静态对象直接设置 ApiResult 参数
     * @param resultCode
     * @param data
     * @return ApiResult
     */
    public static<T> ApiResult<T> failure(ResultCode resultCode, T data) {
        ApiResult result = new ApiResult();
        result.setCode(resultCode.getCode());
        result.setMessage(resultCode.getMessage());
        result.setData(data);
        return result;
    }

}

